package com.loanapp.server.market.webapp.interceptor.login;

import com.loanapp.base.controller.support.HttpKit;
import com.loanapp.server.market.webapp.constant.LoginValidate;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;

@Component
public class LoginInterceptor extends HandlerInterceptorAdapter {


    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (!handler.getClass().isAssignableFrom(HandlerMethod.class)) {
            return true;
        }

        final HandlerMethod handlerMethod = (HandlerMethod) handler;
        final Method method = handlerMethod.getMethod();
        final Class<?> clazz = method.getDeclaringClass();
        if (clazz.isAnnotationPresent(LoginValidate.class) || method.isAnnotationPresent(LoginValidate.class)) {
            System.out.println(method.getName());
            System.out.println("拦截成功！");
        //    request.setAttribute("asd","123123");
        }
        return true;
    }
}
